package com.wlyuan.open.infrastructure.converter;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.core.marker.MappingStatus;
import com.wlyuan.open.dao.entity.OpenApiDO;
import com.wlyuan.open.domain.api.OpenApi;
import com.wlyuan.open.domain.api.utils.MappingMethod;
import com.wlyuan.open.domain.api.utils.MappingOpenApi;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author yuanzheng
 */
public class OpenApiConverter {
    @Mapper(uses = {
            MappingIds.class,
            MappingStatus.class,
            MappingOpenApi.class,
            MappingMethod.class
    })
    public interface Converter {
        OpenApi convert(OpenApiDO source);

        List<OpenApi> convert(List<OpenApiDO> source);

        @InheritInverseConfiguration
        OpenApiDO convert(OpenApi source);
    }

    private static final Converter CONVERTER = Mappers.getMapper(Converter.class);

    public static OpenApiDO convert(OpenApi source) {
        return CONVERTER.convert(source);
    }

    public static List<OpenApi> convert(List<OpenApiDO> source) {
        return CONVERTER.convert(source);
    }

    public static OpenApi convert(OpenApiDO source) {
        return CONVERTER.convert(source);
    }
}
